#ifndef COMMAND_SEARCH_COMMAND_H_
#define COMMAND_SEARCH_COMMAND_H_

#include "command.h"

#ifdef _WIN32
#pragma warning( push )
#pragma warning( disable : 4200 )
#endif

#pragma pack(1)
namespace Cmd
{
        enum //CMD_SEARCH
        {
                SCMD_SEARCH_NULL                        = 0x0000,
                SCMD_SEARCH_USER_BY_USERNAME            = 0x0001,       // 按照用户名查找用户
                SCMD_SEARCH_USER_BY_USERNAME_RES        = 0x0002,       // 返回查找结果
                SCMD_SEARCH_USER_BY_NICKNAME            = 0x0003,       // 按照昵称查找用户
                SCMD_SEARCH_USER_BY_NICKNAME_RES        = 0x0004,       // 返回查找结果
                SCMD_SEARCH_GROUP_BY_ID_REQ             = 0x0005,       // 查找群by群ID
                SCMD_SEARCH_GROUP_BY_ID_RES             = 0x0006,       // 返回查找结果
                SCMD_SEARCH_GROUP_BY_NAME_REQ           = 0x0007,       // 查找群by群名称
                SCMD_SEARCH_GROUP_BY_NAME_RES           = 0x0008,       // 返回查找结果
                SCMD_SEARCH_USER_AND_GROUP_MOBILE       = 0x0009,       // 移动端查询
                SCMD_SEARCH_USER_AND_GROUP_MOBILE_RES   = 0x000A,       // 移动端查询返回
        };
        struct stSearchUserByUserName:
                t_NullCmd
        {
                stSearchUserByUserName():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_USER_BY_USERNAME)
                {
                        bzero(user_name_, sizeof(user_name_));
                        page_ = 0;
                        num_per_page_ = 10;
                }
                BYTE user_name_[MAX_ACCOUNT_SIZE+1];
                WORD page_;
                WORD num_per_page_;
        };
        struct stSearchUserByUserNameRes:
                t_NullCmd
        {
                stSearchUserByUserNameRes():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_USER_BY_USERNAME_RES)
                {
                        size_ = 0;
                        page_ = 0;
                        num_per_page_ = 10;
                        finish_ = 1;
                }
                WORD size_;
                WORD page_;
                WORD num_per_page_;
                BYTE finish_; //0-not finish,1-finish
                struct stSearchResult
                {
                        DWORD user_id_;
                        BYTE user_name_[MAX_ACCOUNT_SIZE+1];
                        BYTE nick_name_[MAX_NAME_SIZE+1];
                        BYTE online_status_;
                } list_[0];
                DWORD getSize() 
                {
                        return sizeof(*this)+size_*sizeof(list_[0]);
                }
        };

        struct stSearchUserByNickName:
                t_NullCmd
        {
                stSearchUserByNickName():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_USER_BY_NICKNAME)
                {
                        bzero(nick_name_, sizeof(nick_name_));
                        page_ = 0;
                        num_per_page_ = 10;
                }
                BYTE nick_name_[MAX_NAME_SIZE+1];
                WORD page_;
                WORD num_per_page_;
        };
        struct stSearchUserByNickNameRes:
                t_NullCmd
        {
                stSearchUserByNickNameRes():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_USER_BY_NICKNAME_RES)
                {
                        size_ = 0;
                        page_ = 0;
                        num_per_page_ = 10;
                        finish_ = 1;
                }
                WORD size_;
                WORD page_;
                WORD num_per_page_;
                BYTE finish_; //0-not finish,1-finish
                struct stSearchResult
                {
                        DWORD user_id_;
                        BYTE user_name_[MAX_ACCOUNT_SIZE+1];
                        BYTE nick_name_[MAX_NAME_SIZE+1];
                        BYTE online_status_;
                } list_[0];
                DWORD getSize() 
                {
                        return sizeof(*this)+size_*sizeof(list_[0]);
                }
        };

        //查找群 相关协议
        struct stSearchGroupByIDReq:
                t_NullCmd
        {
                stSearchGroupByIDReq():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_GROUP_BY_ID_REQ)
                {
                        group_id_ = 0;
                }
                DWORD group_id_;
        };
        struct stSearchGroupByIDRes:
                t_NullCmd
        {
                stSearchGroupByIDRes():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_GROUP_BY_ID_RES)
                {
                        group_id_ = 0;
                        size_ = 0;
                }

                DWORD getSize() const
                {
                        return sizeof(*this) + size_*sizeof(json_[0]);
                }

                DWORD group_id_;
                WORD size_;
                char json_[0];
                // json_ = group_type(uint) + group_name(string) + group_avatar(string) + group_full(boolean)
        };
        struct stSearchGroupByNameReq:
                t_NullCmd
        {
                stSearchGroupByNameReq():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_GROUP_BY_NAME_REQ)
                {
                        bzero(group_name_, sizeof(group_name_));
                        page_ = 0;
                        num_per_page_ = 10;
                }

                char group_name_[MAX_NAME_SIZE+1];
                WORD page_;
                WORD num_per_page_;
        };
        struct stSearchGroupByNameRes:
                t_NullCmd
        {
                stSearchGroupByNameRes():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_GROUP_BY_NAME_RES)
                {
                        page_  = 0;
                        num_per_page_ = 10;
                        finish_ = 1;
                        size_ = 0;
                }

                DWORD getSize() const
                {
                        return sizeof(*this) + size_*sizeof(json_[0]);
                }

                char group_name_[MAX_NAME_SIZE+1];
                WORD page_;
                WORD num_per_page_;
                BYTE finish_;           // 0-not finish,1-finish
                WORD size_;
                char json_[0];
                // json_ = group_info(value)...
                // group_info = group_id(uint) + group_type(uint) + group_name(string) + group_avatar(string) + group_full(boolean)
        };
        struct stSearchUserAndGroupMobile:
                t_NullCmd
        {
                stSearchUserAndGroupMobile():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_USER_AND_GROUP_MOBILE)
                {
                        bzero(query_, sizeof(query_));
                }
                char query_[33];
        };
        struct stSearchUserAndGroupMobileRes:
                t_NullCmd
        {
                stSearchUserAndGroupMobileRes():
                        t_NullCmd(CMD_SEARCH, SCMD_SEARCH_USER_AND_GROUP_MOBILE_RES)
                {
                        bzero(query_, sizeof(query_));
                        finish_ = 0;
                }
                uint32_t size() const
                {
                        return sizeof(*this) + len_*sizeof(result_[0]);
                }
                char query_[33];
                uint8_t finish_; //0-not finish 1-finish
                uint16_t len_;   //result_的长度
                char result_[0];
                // {"usrs-byname":[userinfo], "usrs-bynick":[userinfo], "grps-byname":[groupinfo], "grps-byid":[groupinfo]}
                // userinfo = uid(uint) + acc(string) + nk(string)
                // groupinfo = gid(uint) + name(string)
        };

};//namespace Cmd
#pragma pack()

#ifdef _WIN32
#pragma warning( pop )
#endif

#endif //COMMAND_SEARCH_COMMAND_H_
